import * as api from '@/api/common.js'
const state = {
  allTags: [],                 // 所有标签
  targetTreeData: [],           // 目标树 侧边栏
  targetTreeClickId: '',        // 目标树  当前点击节点id
  targetTreeChecked: [],        // 目标选中节点ID
  targetTreeCheckedName: '',        // 目标选中节点目标名称
  targetTreeSingleId: '',  // 目标选中 单选ID 
  targetTreeIsSingle: false,    //  目标数是否为单选
  pictureTreeChecked: [],        // 图册选中节点ID
  dataTypeTabsId: 2,      // 资料类别  文件类型1是资料2是图片3是视频
  checkedId: [], //资料编辑 
  title: "新增",
  isEmptyForm: false,// 表单页是否一开始清空所有数据
  examining: false, // 是否审核中
  finalCheck: 0,
  checkedDataIds: '', // 批量审核数据ids
  defaultId: 1, // 用户管理设置默认菜单
}

const mutations = {
  setAllTags: (state, allTags) => {
    state.allTags = allTags
  },
  setTargetTreeClickId: (state, id) => {
    state.targetTreeClickId = id
  },
  setTargetTreeChecked: (state, ids) => {
    state.targetTreeChecked = ids
  },
  setTargetTreeCheckedName: (state, data) => {
    state.targetTreeCheckedName = data
  },
  setPictureTreeChecked: (state, data) => {
    state.pictureTreeChecked = data
  },
  setDataTypeTabsId: (state, id) => {
    state.dataTypeTabsId = id
  },
  setTargetTreeIsSingle: (state, data) => {
    state.targetTreeIsSingle = data
  },
  setTargetTreeSingleId: (state, data) => {
    state.targetTreeSingleId = data
  },
  setCheckedId: (state, data) => {
    state.checkedId = data
  },
  setTargetTreeData: (state, data) => {
    state.targetTreeData = data
  },
  setDialogTitle: (state, data) => {
    state.title = data
  },
  setIsEmptyForm: (state, data) => {
    state.isEmptyForm = data
  },
  // 是否审核中
  setExamine: (state, bool) => {
    state.examining = bool
  },
  // 是否终审
  setFinalCheck: (state, type) => {
    state.finalCheck = type
  },
  // 批量审核数据Ids
  setCheckedDataIds: (state, ids) => {
    state.checkedDataIds = ids
  },
  // 用户管理设置默认菜单
  setDefaultId: (state, id) => {
    state.defaultId = id
  }
}

const actions = {
  // 查询所有标签
  async findAllTag({ commit }) {
    let data = await api.findAllTag();
    commit('setAllTags', data)
  },
  // 查询所有目标
  /* async findAllTarget({ commit }) {
    let data = await api.findAllTarget();
    commit('setTargetTreeData', data)
  } */
  async findAllTarget({ commit }) {
    let data = await api.newTargetFindAllByTree();
    commit('setTargetTreeData', data)
  }

}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
